package buildings.dwelling.hotel;

import buildings.Space;
import buildings.Floor;
import buildings.dwelling.DwellingFloor;
import buildings.dwelling.Flat;

public class HotelFloor extends DwellingFloor implements Floor, Cloneable {

    private int stars;
    private int DEFAULT_STARS = 1;

    public HotelFloor(int flatCount) {
        super(flatCount);
        stars = DEFAULT_STARS;
    }

    public HotelFloor(Space[] spaces) {
        super(spaces);
        stars = DEFAULT_STARS;
    }

    public int getStars() {
        return stars;
    }

    public void setStars(int stars) {
        this.stars = stars; 
    }
    
    public String toString() {
        StringBuffer buf = new StringBuffer(this.getClass().getSimpleName() 
                + " (" + stars + ", " + getSpaceCount() + ",");
        for (int i = 0; i < getSpaceCount(); i++) {
            buf.append(" ");
            buf.append(getSpaceByNumber(i));
        }
        buf.append(")");
        return buf.toString();
    }
    
    public boolean equals(Object obj) {
        if(!(obj instanceof HotelFloor ))
            return false;
        boolean isSpacesEquals = true;
        for(int i = 0; i < getSpaceCount(); i++) {
            if(!((HotelFloor)obj).getSpaceByNumber(i).equals(getSpaceByNumber(i))) {
                isSpacesEquals = false;
                break;
            }
        }
        return((((HotelFloor)obj).getStars() == getStars())
                && (((HotelFloor)obj).getSpaceCount() == getSpaceCount())
                && (isSpacesEquals));
    }
    
    public int hashCode() {
        int hash = stars | getSpaceCount();
        for(int i = 0; i < getSpaceCount(); i++) {
            hash |= getSpaceByNumber(i).hashCode();
        }
        return hash;
    }

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
    
    
}
